package com.devshephard.controller;


import com.devshephard.entity.User;
import com.devshephard.mapper.UserMapper;
import com.devshephard.utils.JwtUtil;
import io.jsonwebtoken.Claims;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;
import java.util.logging.Logger;

@RestController
public class SecurityController {

    @Autowired
    UserMapper userMapper;

    @RequestMapping("/hello")
    @ResponseBody
    public String HelloSecurity(){
        return "Hello Secirity";
    }


    @RequestMapping("/userMapper")
    @ResponseBody
    public String userMapper(){
        User user = new User();
        user.setId(UUID.randomUUID().toString());
        userMapper.insert(user);
        List<User> userList = userMapper.selectList(null);
        System.out.println(userList.toString());
        return "Hello Mapper";
    }

    @RequestMapping("/testEncodePassword")
    @ResponseBody
    @Test
    public void testEncodePassword() throws Exception {

        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        String encode = bCryptPasswordEncoder.encode("123456");
        System.out.println(encode);

        System.out.println(bCryptPasswordEncoder.matches("1232456",encode));

        String jwt = JwtUtil.createJWT("123");
        System.out.println(jwt);
        Claims claims = JwtUtil.parseJWT(jwt);
        System.out.println(claims.getSubject());

    }

}
